#===================================================================================#
#                                                 __                                #
#                                                /\ \__                             #
#                    _____   _ __   __  __    ___\ \ ,_\                            #
#                   /\ '__`\/\`'__\/\ \/\ \ /' _ `\ \ \/                            #
#                   \ \ \_\ \ \ \/ \ \ \_\ \/\ \/\ \ \ \_    __   __                #
#                    \ \  __/\ \_\  \/`____ \ \_\ \_\ \__\  /\_\ /\_\               #
#                     \ \ \/  \/_/   `/___/> \/_/\/_/\/__/  \/_/ \/_/               #
#                      \ \_\            /\___/                                      #
#                       \/_/            \/__/                                       #
#                                                                                   #
#===================================================================================#
#@copyright: 2008 by Jeremy Bouillanne
#@license: Apache Public Licence
from __future__ import absolute_import
__revision = '$Revision:  $'[11:-2]

from .rest import fig,img, substitution_image
from matplotlib.mathtext import MathTextParser
import prynt

class mathtext(object):
    default_equation = 'equ-%i'
    inline_color='black' 
    inline_dpi=120 
    inline_fontsize=10
    figure_color='black'
    figure_dpi=120 
    figure_fontsize=14
    __equation_count = 1
    
    def __init__(self):
        pass
    
    def get_new_equation_name(self):
            equ_name = prynt.config.getfilepath(self.default_equation%self.__equation_count, "png")
            self.__equation_count+=1
            return equ_name

__config = mathtext()
    
def equ(equa, name):
    equation_name= __config.get_new_equation_name()
    MathTextParser("bitmap").to_png(equation_name, "$"+equa+" $", __config.inline_color, __config.inline_dpi, __config.inline_fontsize)
    return substitution_image(name, equation_name)
    

def fequ(equa):
    equation_name = __config.get_new_equation_name()
    MathTextParser("bitmap").to_png(equation_name, "$$"+equa+"$$", __config.figure_color, __config.figure_dpi, __config.figure_fontsize)
    return fig(equation_name)
